package com.daxiong.hfs;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

import com.daxiong.hfs.bean.CustomListBean;
import com.daxiong.hfs.bean.MainBean;
import com.daxiong.hfs.bean.ProductBean;
import com.daxiong.hfs.constant.Constant;
import com.daxiong.hfs.util.CommonUtil;

public class ResultActivity extends Activity {

	private MainBean mainBean;

	private ListView listView;

	@Override
	public void onCreate(final Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.result_layout);

		mainBean = //
		(MainBean) //
		CommonUtil.getSerializable(getIntent(), Constant.MAIN_BEAN_KEY);

		listView = (ListView) findViewById(R.id.listView);

		listView.setAdapter(new CustomListBean(this, mainBean.getResultList()));

		listView.setOnItemClickListener(new OnItemClickListener() {
			public void onItemClick( //
					final AdapterView<?> parent, //
					final View view, //
					final int position, //
					final long id //
			) {
				final ProductBean productBean = //
				(ProductBean) listView.getItemAtPosition(position);

				mainBean.setSelect(productBean);

				final Intent intent = //
				new Intent(ResultActivity.this, DetailActivity.class);

				final Bundle bundle = new Bundle();

				bundle.putSerializable(Constant.MAIN_BEAN_KEY, mainBean);

				intent.putExtras(bundle);

				startActivity(intent);
			}
		});
	}
}
